home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / SeqPups / appsrc / fastdnaml.src / fastDNAml.h < prev    next >
Text File  |  1996-07-05  |  9KB  |  256 lines

  1. /*  fastDNAml.h  */
  2.  
  3. #define headerName     "fastDNAml.h"
  4. #define headerVersion  "1.1"
  5. #define headerDate     "September 14, 1994"
  6.  
  7. #ifndef dnaml_h
  8.  
  9. #if  defined(__MWERKS__) || defined(THINK_C)  || defined(MPW)
  10. #define MACINTOSH 1
  11. #endif
  12.  
  13. /*  Compile time switches for various updates to program:
  14.  *    0 gives original version
  15.  *    1 gives new version
  16.  */
  17.  
  18. #define ReturnSmoothedView    1  /* Propagate changes back after smooth */
  19. #define BestInsertAverage     1  /* Build three taxon tree analytically */
  20. #define DeleteCheckpointFile  0  /* Remove checkpoint file when done */
  21.  
  22. #define Debug                 0
  23.  
  24.     /* dgg additions */
  25. #include <time.h>
  26. #define TIMER(x)            clock(x)
  27. #ifndef CLOCKS_PER_SEC
  28.     /* ?? microseconds default for unix clock() ???? */
  29. #define CLOCKS_PER_SEC     1000000.0
  30. #endif
  31. #define TIMETOSECS(time)     (double)(time) / (double)(CLOCKS_PER_SEC) 
  32.  
  33. #ifdef __MWERKS__
  34.     /* Macintosh MetroWerks CodeWarrior flags */
  35. #define NoGetPID                
  36. /*#define NoSTDIN                    /* mimic for stdin/stdout package has broken stdin */
  37. #define HasStrLib                /* for Mac/CodeWar, has strstr, strchr */
  38. char *strstr();   
  39. char *strchr();   
  40. char *index();   
  41. #endif
  42.  
  43. #ifdef MSAPP
  44. #define MSDOS 1
  45. #endif
  46.  
  47. #ifdef MSDOS
  48. #define NoGetPID
  49. #define NoSTDIN
  50. #define HasStrLib
  51. char *strstr();   
  52. char *strchr();   
  53. char *index();   
  54. #endif
  55.  
  56.  
  57. /*  Program constants and parameters  */
  58.  
  59. #define maxcategories   35  /* maximum number of site types */
  60. #define maxlogf        128  /* maximum number of user trees */
  61.  
  62. #define smoothings      32  /* maximum smoothing passes through tree */
  63. #define iterations      10  /* maximum iterations of makenewz per insert */
  64. #define newzpercycle     1  /* iterations of makenewz per tree traversal */
  65. #define nmlngth         10  /* number of characters in species name */
  66. #define deltaz     0.00001  /* test of net branch length change in update */
  67. #define zmin       1.0E-15  /* max branch prop. to -log(zmin) (= 34) */
  68. #define zmax (1.0 - 1.0E-6) /* min branch prop. to 1.0-zmax (= 1.0E-6) */
  69. #define defaultz       0.9  /* value of z assigned as starting point */
  70. #define unlikely  -1.0E300  /* low likelihood for initialization */
  71. #define down             2
  72. #define over            60
  73. #define checkpointname "checkpoint"
  74.  
  75. #define badEval        1.0
  76. #define badZ           0.0
  77. #define badRear         -1
  78. #define badSigma      -1.0
  79.  
  80. #ifndef TRUE
  81. #define TRUE             1
  82. #define FALSE            0
  83. #endif
  84.  
  85. #define treeNone         0
  86. #define treeNewick       1
  87. #define treeProlog       2
  88. #define treePHYLIP       3
  89. #define treeMaxType      3
  90. #define treeDefType  treePHYLIP
  91.  
  92. #define ABS(x)    (((x)<0)   ?  (-(x)) : (x))
  93. #define MIN(x,y)  (((x)<(y)) ?    (x)  : (y))
  94. #define MAX(x,y)  (((x)>(y)) ?    (x)  : (y))
  95. #define LOG(x)    (((x)>0)   ? log(x)  : hang("log domain error"))
  96. #define NINT(x)   ((int) ((x)>0 ? ((x)+0.5) : ((x)-0.5)))
  97.  
  98. #if  ! Vectorize
  99.   typedef  char  yType;
  100. #else
  101.   typedef  int   yType;
  102. #endif
  103.  
  104. typedef  int     boolean;
  105. typedef  double  xtype;
  106.  
  107. typedef  struct  xmantyp {
  108.     struct xmantyp  *prev;
  109.     struct xmantyp  *next;
  110.     struct noderec  *owner;
  111.     xtype           *a, *c, *g, *t;
  112.     } xarray;
  113.  
  114. typedef  struct noderec {
  115.     double           z, z0;
  116.     struct noderec  *next;
  117.     struct noderec  *back;
  118.     int              number;
  119.     xarray          *x;
  120.     int              xcoord, ycoord, ymin, ymax;
  121.     char             name[nmlngth+1]; /*  Space for null termination  */
  122.     yType           *tip;             /*  Pointer to sequence data  */
  123.     } node, *nodeptr;
  124.  
  125. typedef  struct {
  126.     int              numsp;       /* number of species (also tr->mxtips) */
  127.     int              sites;       /* number of input sequence positions */
  128.     yType          **y;           /* sequence data array */
  129.     boolean          freqread;    /* user base frequencies have been read */
  130.     double           freqa, freqc, freqg, freqt,  /* base frequencies */
  131.                         freqr, freqy, invfreqr, invfreqy,
  132.                         freqar, freqcy, freqgr, freqty;
  133.     double           ttratio, xi, xv, fracchange; /* transition/transversion */
  134.     int             *wgt;         /* weight per sequence pos */
  135.     int             *wgt2;        /* weight per pos (booted) */
  136.     int              categs;      /* number of rate categories */
  137.     double           catrat[maxcategories+1]; /* rates per categories */
  138.     int             *sitecat;     /* category per sequence pos */
  139.     } rawDNA;
  140.  
  141. typedef  struct {
  142.     int             *alias;       /* site representing a pattern */
  143.     int             *aliaswgt;    /* weight by pattern */
  144.     int              endsite;     /* # of sequence patterns */
  145.     int              wgtsum;      /* sum of weights of positions */
  146.     int             *patcat;      /* category per pattern */
  147.     double          *patrat;      /* rates per pattern */
  148.     double          *wr;          /* weighted rate per pattern */
  149.     double          *wr2;         /* weight*rate**2 per pattern */
  150.     } crunchedDNA;
  151.  
  152. typedef  struct {
  153.     double           likelihood;
  154.     double          *log_f;       /* info for signif. of trees */
  155.     node           **nodep;
  156.     node            *start;
  157.     node            *outgrnode;
  158.     int              mxtips;
  159.     int              ntips;
  160.     int              nextnode;
  161.     int              opt_level;
  162.     int              log_f_valid; /* log_f value sites */
  163.     int              global;      /* branches to cross in full tree */
  164.     int              partswap;    /* branches to cross in partial tree */
  165.     int              outgr;       /* sequence number to use in rooting tree */
  166.     boolean          prelabeled;  /* the possible tip names are known */
  167.     boolean          smoothed;
  168.     boolean          rooted;
  169.     boolean          userlen;     /* use user-supplied branch lengths */
  170.     rawDNA          *rdta;        /* raw data structure */
  171.     crunchedDNA     *cdta;        /* crunched data structure */
  172.     } tree;
  173.  
  174. typedef struct conntyp {
  175.     double           z;           /* branch length */
  176.     node            *p, *q;       /* parent and child sectors */
  177.     void            *valptr;      /* pointer to value of subtree */
  178.     int              descend;     /* pointer to first connect of child */
  179.     int              sibling;     /* next connect from same parent */
  180.     } connect, *connptr;
  181.  
  182. typedef  struct {
  183.     double           likelihood;
  184.     double          *log_f;       /* info for signif. of trees */
  185.     connect         *links;       /* pointer to first connect (start) */
  186.     node            *start;
  187.     int              nextlink;    /* index of next available connect */
  188.                                   /* tr->start = tpl->links->p */
  189.     int              ntips;
  190.     int              nextnode;
  191.     int              opt_level;   /* degree of branch swapping explored */
  192.     int              scrNum;      /* position in sorted list of scores */
  193.     int              tplNum;      /* position in sorted list of trees */
  194.     int              log_f_valid; /* log_f value sites */
  195.     boolean          prelabeled;  /* the possible tip names are known */
  196.     boolean          smoothed;    /* branch optimization converged? */
  197.     } topol;
  198.  
  199. typedef struct {
  200.     double           best;        /* highest score saved */
  201.     double           worst;       /* lowest score saved */
  202.     topol           *start;       /* starting tree for optimization */
  203.     topol          **byScore;
  204.     topol          **byTopol;
  205.     int              nkeep;       /* maximum topologies to save */
  206.     int              nvalid;      /* number of topologies saved */
  207.     int              ninit;       /* number of topologies initialized */
  208.     int              numtrees;    /* number of alternatives tested */
  209.     boolean          improved;
  210.     } bestlist;
  211.  
  212. typedef  struct {
  213.     long             boot;        /* bootstrap random number seed */
  214.     int              extra;       /* extra output information switch */
  215.     boolean          empf;        /* use empirical base frequencies */
  216.     boolean          interleaved; /* input data are in interleaved format */
  217.     long             jumble;      /* jumble random number seed */
  218.     int              nkeep;       /* number of best trees to keep */
  219.     int              numutrees;   /* number of user trees to read */
  220.     boolean          prdata;      /* echo data to output stream */
  221.     boolean          qadd;        /* test addition without full smoothing */
  222.     boolean          restart;     /* resume addition to partial tree */
  223.     boolean          root;        /* use user-supplied outgroup */
  224.     boolean          trprint;     /* print tree to output stream */
  225.     int              trout;       /* write tree to "treefile" */
  226.     boolean          usertree;    /* use user-supplied trees */
  227.     boolean          userwgt;     /* use user-supplied position weight mask */
  228.     } analdef;
  229.  
  230. typedef  struct {
  231.     double           tipmax;
  232.     int              tipy;
  233.     } drawdata;
  234.  
  235. void  exit();
  236.  
  237. #if  ANSI || MALLOC_VOID
  238.    void *malloc();
  239. #else
  240.    char *malloc();
  241. #endif
  242.  
  243. #define  Malloc(x)  malloc((unsigned) (x))       /* BSD */
  244. /* #define  Malloc(x)  malloc((size_t) (x)) */   /* System V */
  245.  
  246. #define    Free(x)  (void) free((char *) (x))    /* BSD */
  247. /* #define Free(x)  free((void *) (x))      */   /* System V */
  248.  
  249. char *likelihood_key   = "likelihood";
  250. char *ntaxa_key        = "ntaxa";
  251. char *opt_level_key    = "opt_level";
  252. char *smoothed_key     = "smoothed";
  253.  
  254. #define dnaml_h
  255. #endif  /* #if undef dnaml_h */
  256.